<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;

class LoginController extends Controller
{
    //
    public function index()
    {
    	return view("admin.login");
    }
    public function dologin(Request $request)
    {
    	$messages = [
    		"required" => ":attribute 的字段是必要的",
    	];
    	$this->validate($request, [
	        'adminname' => 'required',
	        'adminpassword' => 'required'
    	],$messages);

    	$name = $request->input("adminname");
    	// $pass = $request->input("pwd");
    	$ob = DB::table("adminuser")->where("adminname",$name)->first();
    	if($ob){
    		if($request->input("adminpassword")==$ob->adminpassword){
    			session(["adminuser"=>$ob]);
    			return redirect("/admin");
    		}else{
    			return back()->with("msg","登录失败：密码错误");
    		}
    	}else{
    		return back()->with("msg","登录失败：账号不存在");
    	}
    }
    public function outlogin()
    {
        session()->forget("adminuser");
        return redirect("/admin/login");
    }
}
